﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyLib;

namespace project1
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void btn_Login_Click(object sender, EventArgs e)
        {

            string uid = txtUid.Text.Trim();
            string pwd = txtPwd.Text.Trim();
            if (!string.IsNullOrEmpty(uid) && !string.IsNullOrEmpty(pwd))
            {
                if (MyBussiness.Login(uid, pwd))
                {
                    this.panel2.Visible = false;
                    this.label5.Text = "欢迎用户：" + uid;
                    this.label5.Visible = true;
                    this.panel1.Visible = true;
                }
                else
                {
                    MessageBox.Show("用户名或密码错误！");
                    txtPwd.Text = "";
                    txtPwd.Focus();
                }
            }
            else
            {
                MessageBox.Show("请输入账号或密码！！！");
            }
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                int kc = (int)e.KeyChar;
                if ((kc < 48 || kc > 57) && kc != 8)
                    e.Handled = true;
                if (e.KeyChar == '.')
                {
                    string x = (sender as TextBox).Text + ".";
                    double c = 0.00;
                    bool flag = double.TryParse(x, out c);
                    if (flag && x.LastIndexOf('.') == x.IndexOf('.'))
                    {
                        e.Handled = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string first = textBox1.Text.Trim();
            string second = textBox2.Text.Trim();
            textBox3.Text = GetResult(first, second);
        }

        private string GetResult(string first, string second)
        {
            if (!string.IsNullOrEmpty(first) && !string.IsNullOrEmpty(second))
            {
                try
                {
                    return MyBussiness.Sum(double.Parse(first), double.Parse(second)).ToString();
                }
                catch (Exception ex)
                {
                    return "错误信息：" + ex.Message;
                }
            }
            return "0";
        }
    }
}
